package com.own.center;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.model.Model;

import com.own.core.html.form.Label.OwnLabel;
import com.own.core.html.list.OwnListView;
import com.own.core.html.panel.OwnPanel;

public class HoleSeatGraph extends OwnPanel {

	public HoleSeatGraph(String id, final Hole hole) {

		super(id);
		OwnLabel headerLabel = new OwnLabel("header", hole.getName());
		addOrReplace(headerLabel);
		
		
		List rowSeat = new ArrayList();
		int counter = 0;
		List columeSeat = null;
		for (Object obj : hole.getSeats()) {

			if (counter % hole.getColume() == 0) {

				columeSeat = new ArrayList();
				rowSeat.add(columeSeat);
			}
			columeSeat.add(obj);
			counter++;

		}

		OwnListView seatView = new OwnListView("seat-row", rowSeat) {

			@Override
			protected void populateItem(ListItem item) {
				OwnListView seatRowView = new OwnListView("seat-colume",
						(List) item.getModelObject()) {

					@Override
					protected void populateItem(ListItem seatcolumeItem) {

						Seat seat = (Seat) seatcolumeItem.getModel()
								.getObject();
						if (seat.isActive()) {
							seatcolumeItem.add(new AttributeModifier("class",
									true, new Model("seat")));
						} else {
							seatcolumeItem.add(new AttributeModifier("class",
									true, new Model("seatNotActive")));

						}

						seatcolumeItem.add(new AttributeModifier("title", true,
								new Model(seat.getName())));

					}
				};

				item.add(seatRowView);
			}
		};

		add(seatView);

	}
}
